﻿Public Class AutoExtinction
    Private minutes As Integer
    Private dateactuelle As DateTime
    Private maxSpan As Integer = 1439
    Private Sub ckbExtinction_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ckbExtinction.CheckedChanged
        gpbExtinction.Enabled = ckbExtinction.Checked
    End Sub

    Private Sub nud_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        minutes = CInt(nudHeures.Value * 60 + nudMinutes.Value)
    End Sub

    Private Sub AutoExtinction_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        minutes = CInt(Mainform.TimerStop.TempsRestant)
        Dim min As Integer
        Dim heur As Integer
        heur = Math.DivRem(minutes, 60, min)
        nudHeures.Value = heur
        nudMinutes.Value = min
        Select Case Mainform.TimerStop.ShutdownMode
            Case StopPC.ShutdownModeType.Fermer
                robFermerZV.Checked = True
            Case StopPC.ShutdownModeType.Supendre
                robSuspendre.Checked = True
            Case StopPC.ShutdownModeType.Hiberner
                robHiberner.Checked = True
            Case StopPC.ShutdownModeType.Arreter
                robArreter.Checked = True
        End Select
        ckbExtinction.Checked = Mainform.TimerStop.Actif
        gpbExtinction.Enabled = ckbExtinction.Checked

        dateactuelle = DateTime.Now
        AddHandler nudHeures.ValueChanged, AddressOf nud_ValueChanged
        AddHandler nudMinutes.ValueChanged, AddressOf nud_ValueChanged

    End Sub


    Private Sub btAppliquer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btAppliquer.Click
        If ckbExtinction.Checked Then
            Mainform.TimerStop.Interval = minutes
            If robSuspendre.Checked Then
                Mainform.TimerStop.ShutdownMode = StopPC.ShutdownModeType.Supendre
            ElseIf robHiberner.Checked Then
                Mainform.TimerStop.ShutdownMode = StopPC.ShutdownModeType.Hiberner
            ElseIf robArreter.Checked Then
                Mainform.TimerStop.ShutdownMode = StopPC.ShutdownModeType.Arreter
            Else
                'comment vous etes arrivé là ?
            End If
            Mainform.TimerStop.Lancer()
        Else
            Mainform.TimerStop.Arreter()
        End If
        Me.Close()
    End Sub

    Private Sub btAnnuler_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btAnnuler.Click
        Me.Close()
    End Sub
End Class